package com.ruoyi.business.ledger.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.business.ledger.domain.RealCard;
import com.ruoyi.business.ledger.mapper.RealCardMapper;
import com.ruoyi.business.ledger.service.IRealCardService;
import com.ruoyi.common.core.utils.DateUtils;
import com.ruoyi.common.core.utils.uuid.SnowIdUtil;
import com.ruoyi.common.security.utils.SecurityUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

/**
 * 台账列表Service业务层处理
 *
 * @author lcy
 * @date 2024-09-24
 */
@Service
public class RealCardServiceImpl extends ServiceImpl<RealCardMapper, RealCard> implements IRealCardService {

    @Resource
    private RealCardMapper realCardMapper;

    /**
     * 查询台账列表
     *
     * @param id 台账列表主键
     * @return 台账列表
     */
    @Override
    public RealCard selectRealCardById(String id) {
        return realCardMapper.selectRealCardById(id);
    }

    /**
     * 查询台账列表列表
     *
     * @param realCard 台账列表
     * @return 台账列表
     */
    @Override
    public List<RealCard> selectRealCardList(RealCard realCard) {
        return realCardMapper.selectRealCardList(realCard);
    }

    /**
     * 新增台账列表
     *
     * @param realCard 台账列表
     * @return 结果
     */
    @Override
    @Transactional(rollbackFor =  Exception.class)
    public Object insertRealCard(RealCard realCard) {
        realCard.setId(SnowIdUtil.genSnowId())
                    .setCreateBy(SecurityUtils.getUsername())
                    .setCreateTime(DateUtils.getNowDate())
                    .setUpdateBy(SecurityUtils.getUsername())
                    .setUpdateTime(DateUtils.getNowDate());
        realCardMapper.insert(realCard);
        return realCard.getId();
    }

    /**
     * 修改台账列表
     *
     * @param realCard 台账列表
     * @return 结果
     */
    @Override
    @Transactional(rollbackFor =  Exception.class)
    public int updateRealCard(RealCard realCard) {
        realCard.setUpdateBy(SecurityUtils.getUsername())
                    .setUpdateTime(DateUtils.getNowDate());
        return realCardMapper.updateById(realCard);
    }

    /**
     * 批量删除台账列表
     *
     * @param ids 需要删除的台账列表主键
     * @return 结果
     */
    @Override
    @Transactional(rollbackFor =  Exception.class)
    public int deleteRealCardByIds(String[] ids) {
        return realCardMapper.deleteRealCardByIds(ids);
    }

}
